/*
 * Project CHEN Rendering Engine : /rng.hpp
 * Created: 2021-03-08, Last modified:  2021-03-08
 * 
 * A very simple header file.
 * Provide thread local random number generators for easy use.
 * 
 * Copyright (C) 2021 Hineven (hineven@pku.edu.cn)
 * 
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
#ifndef _H_RNG
#define _H_RNG
#include <random>
#include <thread>
#include "heads.hpp"
namespace chen {
struct _Thrd_t
{    /* thread identifier for Win32 */
    void *_Hnd;    /* Win32 HANDLE */
    unsigned int _Id;
} ;
class RNG {
    std::mt19937 _orng;
public:
    inline RNG () {
        _orng.seed(19260817);
    }
    Float rand01 () {
        return min(
            (Float)(_orng()-_orng.min())/(_orng.max()-_orng.min()),
            float_one_minus
        );
    }
};
extern thread_local RNG rng;
}
#endif
